package com.qf.mes.controlller;

import com.qf.mes.entity.SysUser;
import com.qf.mes.service.SysUserService;
import com.qf.mes.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.UUID;

@RestController
public class SysUserController {
    @Resource
    private SysUserService sysUserService;
    private HashMap<String, Object> map = new HashMap<>( );


    @PostMapping ("/user/login")
    public R login(@RequestBody SysUser sysUser){
        System.out.println("25"+sysUser);
        SysUser user2 = sysUserService.login(sysUser);
        System.out.println(user2);
        String  token = UUID.randomUUID().toString();

        map.put("token",token);
        map.put(token,user2);
        System.out.println(map);
        return R.ok(map);

    }
    @GetMapping("/user/getInfo")
    public R info(String token){
        SysUser user = (SysUser) map.get(token);
        System.out.println(user);


        return R.ok(user);
    }
}
